package javaapplication1;

import java.applet.Applet;

import core.Client;
import core.Speaker;
import core.Settings;
import ui.GUIMessenger;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class WebMessenger extends Applet
{
    public void init()
    {
        int port = Integer.parseInt((String)JOptionPane.showInputDialog(
                    null,
                    "Port",
                    "Port to listen",
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    null,
                    "1000"));
        //System.out.println("port");
		Settings.instance().setPort(port);
		Client.instance().setDaemon(true);
		Client.instance().start();
		Speaker s = new Speaker();
        //System.out.println("speaker");
		Client.instance().setSpeaker(s);
        // // System.out.println("set speaker");
        
        GUIMessenger mainFrame;
		mainFrame = new GUIMessenger(s);
        // System.out.println("main frame");
        mainFrame.setTitle(String.format("%d@%s", port, "127.0.0.1"));
        
        mainFrame.setSize(300, 250);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.setVisible(true);
        //System.out.println("set visible");
    }

    public void stop() {}
}